<?php
/**
 * This is the file to define BaseHandler.
 * 
 * @author	Justin Yoo
 * @version	0.0.1.0001
 * @package	KYR.Core
 * 
 */

//	Checks if this file is called within the framework; otherwise terminates.
if (!defined("IS_FRAMEWORK") || !IS_FRAMEWORK)	header("Location: http://".$_SERVER["HTTP_HOST"]."/error/404");

/**
 * This is class BaseHandler that defines basic properties and methods of each class inherited.
 *
 * Defines basic properties and methods of each class inherited.
 * 
 * @author	Justin Yoo
 * @package	KYR.Core
 * @abstract
 * 
 */
abstract class BaseHandler extends BaseObject
{
	/**
	 * Initiates the BaseHandler class.
	 *
	 * @access	public
	 * @param	Request	$request		Request object that contains page request details.
	 * @param	int		$componentID	ComponentID.
	 *
	 */
	public function __construct($request, $componentID)
	{
		parent::__construct();

		$this->request			= $request;
		$this->existHandler		= false;
		$this->componentID		= $componentID;
		$this->handlerID		= null;
	}

	/**
	 * Checks if the handler exists or not.
	 *
	 * @access	protected
	 * @exception	Throws an Exception while processing a database query.
	 *
	 */
	protected function CheckHandler_()
	{
		$existHandler	= false;
		$db				= null;
		try
		{
			$db = new Database("MySQL");
			$qry = "CALL cms_CheckHandler(";
			$qry .= "'".$db->Quote($this->handlerName)."', ";
			$qry .= $this->componentID;
			$qry .= ")";
			$db->Query($qry);
			$row = $db->Fetch();

			if (isset($row) && count($row) > 0)
			{
				$existHandler			= true;
				$this->existHandler		= true;
				$this->handlerID		= $row["handlerID"];
			}
		}
		catch (Exeption $ex) { throw $ex; }
		return $existHandler;
	}
	
	/**
	 * Processes the handler.
	 *
	 * @access	public
	 * @param	array	$variables	Set of data to be stored by the component.
	 * @abstract
	 *
	 */
	abstract public function ProcessHandler(&$variables);
	
	/**
	 * Processe the handler.
	 *
	 * @access	protected
	 * @param	array	$variables	Set of data to be stored by the component.
	 *
	 */
	protected function ProcessHandler_(&$variables)
	{
	}

	/**
	 * Gets the list of object names to be loaded.
	 *
	 * @access	protected
	 *
	 */
	protected function GetObjectNames_($type) {}
}
?>
